<?php
/*
	预约订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','mid','order_type','ordersn','price','status','pay_id','print_status','createtime','is_pay');
	$list=pdo_getslice('jy_meye_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$item['member']['nickname'];
			$item['avatar']=$item['member']['avatar'];
			$item['price']=$item['price'];
			$item['is_pay']=$item['is_pay'] ? '已付款':'未付款';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'预约列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'nickname','title'=>'顾客信息','type'=>'string'),
			array('name'=>'order_type','title'=>'订单类型','type'=>'radio','options'=>'order_types'),
			array('name'=>'price','title'=>'订单金额','type'=>'string'),
			array('name'=>'status','title'=>'订单状态','type'=>'radio','options'=>'order_status','set'=>'set'),
			array('name'=>'is_pay','title'=>'是否已付款','type'=>'status_string'),
			array('name'=>'print_status','title'=>'打印状态','type'=>'radio','options'=>'print_statuss'),
			array('name'=>'createtime','title'=>'订单创建时间','type'=>'time'),
		),'action'=>array(
			//array('op'=>'print','type'=>'post','title'=>'打印订单'),
			array('op'=>'detail','type'=>'href','title'=>'订单详情'),
		)),
	);
	$return['htmls']=$htmls;
	$return['print_statuss']=$this->type__print_status();
	$return['order_status']=$this->type__order_status();
	$return['order_types']=$this->type__order();
	exi($return);
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['status'])){
		$update['status']=intval($post['status']);
	}
	if($update){
		pdo_update('jy_meye_order',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('修改订单状态成功！');
}
if($_RQ['op']=='detail'){
	$return=array();
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$item=pdo_get('jy_meye_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$item['member']=model('core/member')->detail($item['mid'],array('nickname','mobile','avatar'));
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'look'=>array(
			array('name'=>'member.nickname','title'=>'顾客信息','type'=>'string'),
			array('name'=>'order_type','title'=>'订单类型','type'=>'radio','options'=>'order_types'),
			array('name'=>'price','title'=>'订单金额','type'=>'string'),
			array('name'=>'status','title'=>'订单状态','type'=>'radio','options'=>'order_status','set'=>'set'),
			array('name'=>'is_pay','title'=>'是否已付款','type'=>'radio','options'=>'order_pay_status'),
			array('name'=>'print_status','title'=>'打印状态','type'=>'radio','options'=>'print_statuss'),
			array('name'=>'createtime','title'=>'订单创建时间','type'=>'time'),
		)
	);
	$return['htmls']=$htmls;
	$return['print_statuss']=$this->type__print_status();
	$return['order_status']=$this->type__order_status();
	$return['order_pay_status']=array(
		'0'=>'待付款',
		'1'=>'已付款',
	);
	$return['order_types']=$this->type__order();
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_meye_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('订单删除成功！');
}